package main

import (
	"fmt"
	"github.com/micro/go-micro/client/selector"
	"github.com/micro/go-micro/registry"
	"github.com/micro/go-plugins/registry/consul"
	"log"
	"time"
)

//func callAPI(s selector.Selector) {
//	myClient := http.NewClient(
//		client.Selector(s),
//		)
//}

func main() {
	consulReg := consul.NewRegistry(
			registry.Addrs("127.0.0.1:8500"),
		)
	//mySelector := selector.NewSelector(
	//	selector.Registry(consulReg),
	//	selector.SetStrategy(selector.RoundRobin),	//轮询模式
	//	)

	for{
		getService,err := consulReg.GetService("prodservice")
		if err != nil{
			log.Fatalln(err)
		}
		//next := selector.Random(getService) //随机
		next := selector.RoundRobin(getService)	//轮询
		node,err := next()
		if err != nil{
			log.Fatalln(err)
		}
		fmt.Println(node.Id,node.Address)
		time.Sleep(time.Second * 1)
	}

}
